<!DOCTYPE html>
<html lang=zh>
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-transform">
  <meta http-equiv="Cache-Control" content="no-siteapp">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no,email=no,adress=no">
  <!-- Color theme for statusbar -->
  <meta name="theme-color" content="#000000">
  <!-- 强制页面在当前窗口以独立页面显示,防止别人在框架里调用页面 -->
  <meta http-equiv="window-target" content="_top">
  
  
  <title>01-深圳市罗湖区-中科软面试总结 | 山岚 - 90码农历险记</title>
  <meta name="description" content="基本信息时间：2019年7月17日14点30 地点：深圳市，罗湖区，爵士大厦23层，17-18室 公司：中科软科技股份有限公司 职位：Java开发工程师 面试官：黄利刚 办公环境：办公环境很一般，估计不到30㎡坐满了人，每个人一个格子桌连在一起，脑补下大学机房的环境，可能更紧凑。 面试流程：给HR看简历，可能是根据简历给你发试卷和基本信息调查表。特别注明试卷和调查表、答案纸是分开的，不是直接填在试">
<meta name="keywords" content="Java面试题">
<meta property="og:type" content="article">
<meta property="og:title" content="01-深圳市罗湖区-中科软面试总结">
<meta property="og:url" content="https://blog.gobyte.cn/post/4a74da6f.html">
<meta property="og:site_name" content="山岚博客">
<meta property="og:description" content="基本信息时间：2019年7月17日14点30 地点：深圳市，罗湖区，爵士大厦23层，17-18室 公司：中科软科技股份有限公司 职位：Java开发工程师 面试官：黄利刚 办公环境：办公环境很一般，估计不到30㎡坐满了人，每个人一个格子桌连在一起，脑补下大学机房的环境，可能更紧凑。 面试流程：给HR看简历，可能是根据简历给你发试卷和基本信息调查表。特别注明试卷和调查表、答案纸是分开的，不是直接填在试">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://wx2.sinaimg.cn/large/96e311f0gy1g54e4h8rdtj20dj07baeq.jpg">
<meta property="og:updated_time" content="2019-12-10T08:14:59.803Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="01-深圳市罗湖区-中科软面试总结">
<meta name="twitter:description" content="基本信息时间：2019年7月17日14点30 地点：深圳市，罗湖区，爵士大厦23层，17-18室 公司：中科软科技股份有限公司 职位：Java开发工程师 面试官：黄利刚 办公环境：办公环境很一般，估计不到30㎡坐满了人，每个人一个格子桌连在一起，脑补下大学机房的环境，可能更紧凑。 面试流程：给HR看简历，可能是根据简历给你发试卷和基本信息调查表。特别注明试卷和调查表、答案纸是分开的，不是直接填在试">
<meta name="twitter:image" content="https://wx2.sinaimg.cn/large/96e311f0gy1g54e4h8rdtj20dj07baeq.jpg">
  <!-- Canonical links -->
  <link rel="canonical" href="https://blog.gobyte.cn/post/4a74da6f.html">
  
    <link rel="alternate" href="/atom.xml" title="山岚博客" type="application/atom+xml">
  
  
    <link rel="icon" href="/shan-2.png" type="image/x-icon">
  
  <link rel="stylesheet" href="/css/style.css">
  
  
  
  
</head>


<body class="main-center theme-black" itemscope itemtype="http://schema.org/WebPage">
  <header class="header" itemscope itemtype="http://schema.org/WPHeader">
  <div class="slimContent">
    <div class="navbar-header">
      
      
      <div class="profile-block text-center">
        <a id="avatar" href="https://github.com/shanlanCoding" target="_blank">
          <img class="img-circle img-rotate" src="/images/ha-002-small.png" width="200" height="200">
        </a>
        <h2 id="name" class="hidden-xs hidden-sm">山岚</h2>
        <h3 id="title" class="hidden-xs hidden-sm hidden-md">半吊子全栈开发者</h3>
        <small id="location" class="text-muted hidden-xs hidden-sm"><i class="icon icon-map-marker"></i> Work in 0755; Home is in 0713</small>
      </div>
      
      <div class="search" id="search-form-wrap">

    <form class="search-form sidebar-form">
        <div class="input-group">
            <input type="text" class="search-form-input form-control" placeholder="搜索" />
            <span class="input-group-btn">
                <button type="submit" class="search-form-submit btn btn-flat" onclick="return false;"><i class="icon icon-search"></i></button>
            </span>
        </div>
    </form>
    <div class="ins-search">
  <div class="ins-search-mask"></div>
  <div class="ins-search-container">
    <div class="ins-input-wrapper">
      <input type="text" class="ins-search-input" placeholder="想要查找什么..." x-webkit-speech />
      <button type="button" class="close ins-close ins-selectable" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
    </div>
    <div class="ins-section-wrapper">
      <div class="ins-section-container"></div>
    </div>
  </div>
</div>


</div>
      <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <nav id="main-navbar" class="collapse navbar-collapse" itemscope itemtype="http://schema.org/SiteNavigationElement" role="navigation">
      <ul class="nav navbar-nav main-nav menu-highlight">
        
        
        <li class="menu-item menu-item-home">
          <a href="/.">
            
            <i class="icon icon-home-fill"></i>
            
            <span class="menu-title">首页</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/">
            
            <i class="icon icon-archives-fill"></i>
            
            <span class="menu-title">归档</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/">
            
            <i class="icon icon-folder"></i>
            
            <span class="menu-title">分类</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/">
            
            <i class="icon icon-tags"></i>
            
            <span class="menu-title">标签</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-links">
          <a href="/links/">
            
            <i class="icon icon-friendship"></i>
            
            <span class="menu-title">友链</span>
          </a>
        </li>
        
      </ul>
      
	
    <ul class="social-links">
    	
        <li><a href="https://github.com/shanlanCoding" target="_blank" title="Github" data-toggle=tooltip data-placement=top><i class="icon icon-github"></i></a></li>
        
        <li><a href="http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=CWRgen1se2phZnxJeHgnamZk" target="_blank" title="Email" data-toggle=tooltip data-placement=top><i class="icon icon-email"></i></a></li>
        
    </ul>

    </nav>
  </div>
</header>

  
    <aside class="sidebar" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    
      <div class="widget">
    <h3 class="widget-title">公告</h3>
    <div class="widget-body">
        <div id="board">
            <div class="content">
                <p>欢迎交流与分享经验，知无不言言无不尽!</p>
            </div>
        </div>
    </div>
</div>

    
      
  <div class="widget">
    <h3 class="widget-title">分类</h3>
    <div class="widget-body">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/Java/">Java</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/JavaScript/">JavaScript</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/windows/">windows</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/前端/">前端</a><span class="category-list-count">9</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/博客优化/">博客优化</a><span class="category-list-count">7</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/变得更好/">变得更好</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/心情/">心情</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/手机/">手机</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/服务器/">服务器</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/求职/">求职</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/骚操作/">骚操作</a><span class="category-list-count">3</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签</h3>
    <div class="widget-body">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/AutoJs/">AutoJs</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Git/">Git</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Hexo/">Hexo</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Java/">Java</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/JavaScript/">JavaScript</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Java面试题/">Java面试题</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/React/">React</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/React教程/">React教程</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/centOS/">centOS</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java基础/">java基础</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java集合框架/">java集合框架</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linux/">linux</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nginx/">nginx</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/vue/">vue</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/windows-10/">windows 10</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/人脸识别/">人脸识别</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/博客优化/">博客优化</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/吐槽/">吐槽</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/小米6/">小米6</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/思维改变/">思维改变</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/自定义手机号/">自定义手机号</a><span class="tag-list-count">1</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签云</h3>
    <div class="widget-body tagcloud">
      <a href="/tags/AutoJs/" style="font-size: 13.2px;">AutoJs</a> <a href="/tags/Git/" style="font-size: 13.4px;">Git</a> <a href="/tags/Hexo/" style="font-size: 13.8px;">Hexo</a> <a href="/tags/Java/" style="font-size: 13px;">Java</a> <a href="/tags/JavaScript/" style="font-size: 13.2px;">JavaScript</a> <a href="/tags/Java面试题/" style="font-size: 13.6px;">Java面试题</a> <a href="/tags/React/" style="font-size: 14px;">React</a> <a href="/tags/React教程/" style="font-size: 13px;">React教程</a> <a href="/tags/centOS/" style="font-size: 13px;">centOS</a> <a href="/tags/java基础/" style="font-size: 13px;">java基础</a> <a href="/tags/java集合框架/" style="font-size: 13px;">java集合框架</a> <a href="/tags/linux/" style="font-size: 13px;">linux</a> <a href="/tags/nginx/" style="font-size: 13.2px;">nginx</a> <a href="/tags/vue/" style="font-size: 13px;">vue</a> <a href="/tags/windows-10/" style="font-size: 13px;">windows 10</a> <a href="/tags/人脸识别/" style="font-size: 13px;">人脸识别</a> <a href="/tags/博客优化/" style="font-size: 13px;">博客优化</a> <a href="/tags/吐槽/" style="font-size: 13px;">吐槽</a> <a href="/tags/小米6/" style="font-size: 13px;">小米6</a> <a href="/tags/思维改变/" style="font-size: 13px;">思维改变</a> <a href="/tags/自定义手机号/" style="font-size: 13px;">自定义手机号</a>
    </div>
  </div>

    
      
  <div class="widget">
    <h3 class="widget-title">归档</h3>
    <div class="widget-body">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/12/">十二月 2019</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/11/">十一月 2019</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/10/">十月 2019</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/09/">九月 2019</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/08/">八月 2019</a><span class="archive-list-count">11</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/07/">七月 2019</a><span class="archive-list-count">9</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/06/">六月 2019</a><span class="archive-list-count">9</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget-body">
      <ul class="recent-post-list list-unstyled no-thumbnail">
        
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/categories/前端/">前端</a>
              </p>
              <p class="item-title">
                <a href="/post/7080982b.html" class="title">AntD的一个警告解决方法：defaultvalue is invalid for getfielddecorator will set value please use option.initialvalue instead</a>
              </p>
              <p class="item-date">
                <time datetime="2019-12-07T08:58:03.000Z" itemprop="datePublished">2019-12-07</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/categories/JavaScript/">JavaScript</a>
              </p>
              <p class="item-title">
                <a href="/post/cbc43a97.html" class="title">海信A5自动阅读打卡签到工具软件脚本</a>
              </p>
              <p class="item-date">
                <time datetime="2019-12-06T09:03:39.000Z" itemprop="datePublished">2019-12-06</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/categories/JavaScript/">JavaScript</a>
              </p>
              <p class="item-title">
                <a href="/post/ae3d322e.html" class="title"> AutoJs获取的Text文本是乱码|Android爬虫反字体屏蔽乱码解决方案 </a>
              </p>
              <p class="item-date">
                <time datetime="2019-11-23T03:50:19.000Z" itemprop="datePublished">2019-11-23</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/categories/服务器/">服务器</a>
              </p>
              <p class="item-title">
                <a href="/post/1a22163b.html" class="title">GitHub克隆clone太慢添加代理加速访问</a>
              </p>
              <p class="item-date">
                <time datetime="2019-11-13T03:51:13.000Z" itemprop="datePublished">2019-11-13</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/categories/心情/">心情</a>
              </p>
              <p class="item-title">
                <a href="/post/d90e4430.html" class="title">奇葩公司每周晚上占用下班时间开会、团建（跑步）</a>
              </p>
              <p class="item-date">
                <time datetime="2019-11-11T06:36:16.000Z" itemprop="datePublished">2019-11-11</time>
              </p>
            </div>
          </li>
          
      </ul>
    </div>
  </div>
  

    
  </div>
</aside>

  
  
<aside class="sidebar sidebar-toc collapse" id="collapseToc" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    <nav id="toc" class="article-toc">
      <h3 class="toc-title">文章目录</h3>
      <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#基本信息"><span class="toc-number">1.</span> <span class="toc-text">基本信息</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#试卷"><span class="toc-number">2.</span> <span class="toc-text">试卷</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#考题回忆"><span class="toc-number">3.</span> <span class="toc-text">考题回忆</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-选择题记不住，印象最深的就是让你人脑运行Java，考你Java的作用域，所以不写总结"><span class="toc-number">3.0.0.1.</span> <span class="toc-text">1.选择题记不住，印象最深的就是让你人脑运行Java，考你Java的作用域，所以不写总结</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-String和StringBuffer以及StringBuilder，哪个效率高？为什么？"><span class="toc-number">3.0.0.2.</span> <span class="toc-text">2. String和StringBuffer以及StringBuilder，哪个效率高？为什么？</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-反射是什么？如何用反射？反射实例化类的3个常用方法？"><span class="toc-number">3.0.0.3.</span> <span class="toc-text">3.反射是什么？如何用反射？反射实例化类的3个常用方法？</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#总结："><span class="toc-number">3.0.1.</span> <span class="toc-text">总结：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#拓展知识："><span class="toc-number">3.0.2.</span> <span class="toc-text">拓展知识：</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#4-反射怎么获取公私有方法、字段？"><span class="toc-number">3.0.2.1.</span> <span class="toc-text">4.反射怎么获取公私有方法、字段？</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#被操作的对象-Student-class"><span class="toc-number">3.0.2.1.1.</span> <span class="toc-text">被操作的对象 Student.class</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#4-1-通过getMethods-遍历所有公开方法"><span class="toc-number">3.0.2.1.2.</span> <span class="toc-text">4.1 通过getMethods() 遍历所有公开方法</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#4-2-通过getDeclaredMethods-遍历所有公开-私有方法"><span class="toc-number">3.0.2.1.3.</span> <span class="toc-text">4.2 通过getDeclaredMethods() 遍历所有公开/私有方法</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#4-3调用指定共有方法"><span class="toc-number">3.0.2.1.4.</span> <span class="toc-text">4.3调用指定共有方法</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#4-4-调用私有方法"><span class="toc-number">3.0.2.1.5.</span> <span class="toc-text">4.4 调用私有方法</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#参考资料："><span class="toc-number">3.0.3.</span> <span class="toc-text">参考资料：</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#总结"><span class="toc-number">4.</span> <span class="toc-text">总结</span></a></li></ol>
    </nav>
  </div>
</aside>

<main class="main" role="main">
  <div class="content">
  <article id="post-01-深圳罗湖中科软面试总结" class="article article-type-post" itemscope itemtype="http://schema.org/BlogPosting">
    
    <div class="article-header" name="标题头部>
      
        
  
    <h1 class="article-title" itemprop="name">
      01-深圳市罗湖区-中科软面试总结
    </h1>
  

      
      <div class="article-meta">
        <span class="article-date">
    <i class="icon icon-calendar-check"></i>
	<a href="/post/4a74da6f.html" class="article-date">
	  <time datetime="2019-07-18T14:37:55.000Z" itemprop="datePublished">2019-07-18</time>
	</a>
</span>
        
  <span class="article-category">
    <i class="icon icon-folder"></i>
    <a class="article-category-link" href="/categories/求职/">求职</a>
  </span>

        
  <span class="article-tag">
    <i class="icon icon-tags"></i>
	<a class="article-tag-link" href="/tags/Java面试题/">Java面试题</a>
  </span>


        
	<span class="article-read hidden-xs">
	    <i class="icon icon-eye-fill" aria-hidden="true"></i>
	    <span id="busuanzi_container_page_pv">
			<span id="busuanzi_value_page_pv">0</span>
		</span>
	</span>


	<span class="article-read hidden-xs">
    	<i class="icon icon-eye-fill" aria-hidden="true"></i>
    	<span id="/post/4a74da6f.html" class="leancloud_visitors"  data-flag-title="01-深圳市罗湖区-中科软面试总结">
			<span class="leancloud-visitors-count">0</span>
		</span>
    </span>

        <span class="post-comment"><i class="icon icon-comment"></i> <a href="/post/4a74da6f.html#comments" class="article-comment-link">评论</a></span>
        
      </div>
    </div>
    <div class="article-entry marked-body" itemprop="articleBody" name="正文">
      
        <h1 id="基本信息"><a href="#基本信息" class="headerlink" title="基本信息"></a>基本信息</h1><p>时间：2019年7月17日14点30</p>
<p>地点：深圳市，罗湖区，爵士大厦23层，17-18室</p>
<p>公司：中科软科技股份有限公司</p>
<p>职位：Java开发工程师</p>
<p>面试官：黄利刚</p>
<p>办公环境：办公环境很一般，估计不到30㎡坐满了人，每个人一个格子桌连在一起，脑补下大学机房的环境，可能更紧凑。</p>
<p>面试流程：给HR看简历，可能是根据简历给你发试卷和基本信息调查表。特别注明试卷和调查表、答案纸是分开的，不是直接填在试卷上。写完答案以后HR就叫了面试官进行面试，这里说下这位面试官。虽然看起来他技术很厉害（谢顶），但是说话有气无力，声音非常小而且普通话也不标准。声音小到我每个问题都听不见不得不提醒他，<strong>体验非常的差。</strong></p>
<h1 id="试卷"><a href="#试卷" class="headerlink" title="试卷"></a>试卷</h1><p>这里夸一下这家公司，试卷比较正常，都是基础的题目，一共分为三大类：</p>
<ol>
<li>选择题，考察基本语法和人脑运行Java代码</li>
<li>简答题，考察框架知识，以及基本的常用的Api</li>
<li>SQL题，给两张表，然后根据表的内容来手写SQL</li>
</ol>
<h1 id="考题回忆"><a href="#考题回忆" class="headerlink" title="考题回忆"></a>考题回忆</h1><h4 id="1-选择题记不住，印象最深的就是让你人脑运行Java，考你Java的作用域，所以不写总结"><a href="#1-选择题记不住，印象最深的就是让你人脑运行Java，考你Java的作用域，所以不写总结" class="headerlink" title="1.选择题记不住，印象最深的就是让你人脑运行Java，考你Java的作用域，所以不写总结"></a>1.选择题记不住，印象最深的就是让你人脑运行Java，考你Java的作用域，所以不写总结</h4><h4 id="2-String和StringBuffer以及StringBuilder，哪个效率高？为什么？"><a href="#2-String和StringBuffer以及StringBuilder，哪个效率高？为什么？" class="headerlink" title="2. String和StringBuffer以及StringBuilder，哪个效率高？为什么？"></a>2. String和StringBuffer以及StringBuilder，哪个效率高？为什么？</h4><p>我之前仅知道StringBuffer快，但是为什么快我不知道，更没有通过StringBuilder。下面贴出网上的答案：</p>
<blockquote>
<p>在 Java 中<strong>字符串</strong>属于<strong>对象</strong>，Java 提供了 <strong>String 类来创建和操作字符串</strong>。需要注意的是，<strong>String的值是不可变的</strong>，这就导致每次对String的操作<strong>都会生成新的String对象</strong>，这样不仅效率低下，而且大量<strong>浪费有限的内存空间</strong>。</p>
<p>StringBuilder 类在 <strong>Java 5</strong> 中被提出，它和 StringBuffer 之间的最大不同在于 StringBuilder 的方法不是线程安全的（不能同步访问）。</p>
<p><img src="//wx2.sinaimg.cn/large/96e311f0gy1g54e4h8rdtj20dj07baeq.jpg" alt="三者的区别"></p>
<p>小结：</p>
<p>（1）如果要操作少量的数据用 String；</p>
<p>（2）多线程操作字符串缓冲区下操作大量数据 StringBuffer；</p>
<p>（3）单线程操作字符串缓冲区下操作大量数据 StringBuilder。</p>
</blockquote>
<h4 id="3-反射是什么？如何用反射？反射实例化类的3个常用方法？"><a href="#3-反射是什么？如何用反射？反射实例化类的3个常用方法？" class="headerlink" title="3.反射是什么？如何用反射？反射实例化类的3个常用方法？"></a>3.反射是什么？如何用反射？反射实例化类的3个常用方法？</h4><p>我仅了解反射的原理，实际方法也只是学习的时候临摹了几次，所以不记得如何使用反射，下面贴出完整答案：</p>
<blockquote>
<p>高端点说：动态加载一个类对象，然后得到这个类对象的<strong>公私有方法、字段</strong>。那么问题是怎么加载这个类对象？所以就要用到反射的实例方法，一共有三种：</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 1. 通过Object的getClass()加载一个实例对象</span></span><br><span class="line">Studnet stu = <span class="keyword">new</span> Student();</span><br><span class="line">Class cls = stu.getClass();</span><br><span class="line"><span class="comment">// 2. 通过类名</span></span><br><span class="line">Class stu = Student.class;</span><br><span class="line"><span class="comment">// 3. 通过类的具体路径，加载</span></span><br><span class="line">Class&lt;?&gt; clz = Class.forName(<span class="string">"fs.Student"</span>);</span><br></pre></td></tr></table></figure>

<blockquote>
<h3 id="总结："><a href="#总结：" class="headerlink" title="总结："></a>总结：</h3><ol>
<li>第一种对象都有了，还要反射干嘛？</li>
<li>需要导包，否则编译错误。</li>
<li>一般是通过forName，参数是一个类的路径，可以写在配置文件里。</li>
</ol>
<p>资料：<a href="https://blog.csdn.net/sinat_38259539/article/details/71799078" target="_blank" rel="noopener">Java基础之—反射（非常重要）</a></p>
</blockquote>
<h3 id="拓展知识："><a href="#拓展知识：" class="headerlink" title="拓展知识："></a>拓展知识：</h3><h4 id="4-反射怎么获取公私有方法、字段？"><a href="#4-反射怎么获取公私有方法、字段？" class="headerlink" title="4.反射怎么获取公私有方法、字段？"></a>4.反射怎么获取公私有方法、字段？</h4><p>获取方法以及调用思路如下：</p>
<ol>
<li>获得Class对象，通过上述的三种方法即可，推荐使用：<code>Class.forName(&quot;xxx.student&quot;)</code></li>
<li>通过Class对象，生成并强转成对象实例：<code>(Student) aClass.newInstance();</code></li>
<li>通过Class对象，来获取方法数组：<code>aClass.getMethods()</code></li>
<li>通过方法数组遍历出所有的方法，一般使用<code>forEach</code>遍历</li>
</ol>
<h5 id="被操作的对象-Student-class"><a href="#被操作的对象-Student-class" class="headerlink" title="被操作的对象 Student.class"></a>被操作的对象 Student.class</h5><details>
    <summary>点击查看完整Student代码</summary>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> reflect;</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Student</span> </span>&#123;</span><br><span class="line">    String name;</span><br><span class="line">    <span class="keyword">int</span> age;</span><br><span class="line">    Boolean mySex; <span class="comment">// false 女；true 男</span></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="title">Student</span><span class="params">(String name, <span class="keyword">int</span> age, Boolean mySex)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.name = name;</span><br><span class="line">        <span class="keyword">this</span>.age = age;</span><br><span class="line">        <span class="keyword">this</span>.mySex = mySex;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">say</span><span class="params">(String str)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (str.equals(<span class="string">""</span>))</span><br><span class="line">            System.err.println(<span class="string">"你什么都没说."</span>);</span><br><span class="line">        System.out.println(str);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">mySay</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        System.out.println(<span class="string">"这是私有方法"</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getName</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> name;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setName</span><span class="params">(String name)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.name = name;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">getAge</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> age;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setAge</span><span class="params">(<span class="keyword">int</span> age)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.age = age;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">toString</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">"Student&#123;"</span> +</span><br><span class="line">                <span class="string">"name='"</span> + name + <span class="string">'\''</span> +</span><br><span class="line">                <span class="string">", age="</span> + age +</span><br><span class="line">                <span class="string">", mySex="</span> + mySex +</span><br><span class="line">                <span class="string">'&#125;'</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

</details>


<h5 id="4-1-通过getMethods-遍历所有公开方法"><a href="#4-1-通过getMethods-遍历所有公开方法" class="headerlink" title="4.1 通过getMethods() 遍历所有公开方法"></a>4.1 通过getMethods() 遍历所有公开方法</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 取得Class</span></span><br><span class="line">Class&lt;?&gt; aClass = Class.forName(<span class="string">"reflect.Student"</span>);</span><br><span class="line"><span class="comment">// 通过Class生成对象</span></span><br><span class="line">Student stu = (Student) aClass.newInstance();</span><br><span class="line"><span class="comment">// 通过Class取到公开方法数组</span></span><br><span class="line">Method[] methods = aClass.getMethods();</span><br><span class="line"><span class="comment">// 遍历方法数组，得到所有的方法名</span></span><br><span class="line"><span class="keyword">for</span> (Method m : methods) &#123;</span><br><span class="line">    System.err.println(<span class="string">"公有方法："</span> + m.getName());</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 打印结果</span></span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">公有方法：toString</span></span><br><span class="line"><span class="comment">公有方法：getName</span></span><br><span class="line"><span class="comment">公有方法：setName</span></span><br><span class="line"><span class="comment">公有方法：getAge</span></span><br><span class="line"><span class="comment">公有方法：say</span></span><br><span class="line"><span class="comment">公有方法：setAge</span></span><br><span class="line"><span class="comment">公有方法：wait</span></span><br><span class="line"><span class="comment">公有方法：wait</span></span><br><span class="line"><span class="comment">公有方法：wait</span></span><br><span class="line"><span class="comment">公有方法：equals</span></span><br><span class="line"><span class="comment">公有方法：hashCode</span></span><br><span class="line"><span class="comment">公有方法：getClass</span></span><br><span class="line"><span class="comment">公有方法：notify</span></span><br><span class="line"><span class="comment">公有方法：notifyAll</span></span><br><span class="line"><span class="comment">*/</span></span><br></pre></td></tr></table></figure>

<h5 id="4-2-通过getDeclaredMethods-遍历所有公开-私有方法"><a href="#4-2-通过getDeclaredMethods-遍历所有公开-私有方法" class="headerlink" title="4.2 通过getDeclaredMethods() 遍历所有公开/私有方法"></a>4.2 通过getDeclaredMethods() 遍历所有公开/私有方法</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 取得Class</span></span><br><span class="line">Class&lt;?&gt; aClass = Class.forName(<span class="string">"reflect.Student"</span>);</span><br><span class="line"><span class="comment">// 包含了私有和公有方法</span></span><br><span class="line">Method[] declaredMethods = aClass.getDeclaredMethods();</span><br><span class="line"><span class="comment">// forEach遍历</span></span><br><span class="line"><span class="keyword">for</span> (Method dm : declaredMethods) &#123;</span><br><span class="line">    System.err.println(<span class="string">"私有方法："</span> + dm.getName());</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 打印结果</span></span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">私有方法：toString</span></span><br><span class="line"><span class="comment">私有方法：getName</span></span><br><span class="line"><span class="comment">私有方法：setName</span></span><br><span class="line"><span class="comment">私有方法：mySay</span></span><br><span class="line"><span class="comment">私有方法：getAge</span></span><br><span class="line"><span class="comment">私有方法：say</span></span><br><span class="line"><span class="comment">私有方法：setAge</span></span><br><span class="line"><span class="comment">*/</span></span><br></pre></td></tr></table></figure>

<h5 id="4-3调用指定共有方法"><a href="#4-3调用指定共有方法" class="headerlink" title="4.3调用指定共有方法"></a>4.3调用指定共有方法</h5><ol>
<li>得到class对象，通常使用Class.forName()</li>
<li>通过class对象的newInstance() 得到一个实例，并把这个实例强转成你需要的对象</li>
<li>通过class对象的getMethod()，拿到你要调用的方法；第一个参数是需要调用的方法名，第二个是该方法的参数类型的Class。如果方法没有参数，则应该填写null，比如getName()就没有参数</li>
<li>通过指定方法的invoke()，第一个参数传入该方法的对象，第二个参数是该方法的参数，如果没有则不填写</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">function1</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        <span class="comment">// 得到class</span></span><br><span class="line">        Class&lt;?&gt; aClass = Class.forName(<span class="string">"reflect.Student"</span>);</span><br><span class="line">        <span class="comment">// 创建实例，并强转成学生对象</span></span><br><span class="line">        Student student = (Student) aClass.newInstance();</span><br><span class="line">        student.setName(<span class="string">"赵云"</span>);</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 得到指定的方法</span></span><br><span class="line">        Method say = aClass.getMethod(<span class="string">"say"</span>, String.class);</span><br><span class="line">        <span class="comment">// 第一个参数：方法名；第二个参数：方法的参数类型。这里的getName()它不需要参数，所以为null</span></span><br><span class="line">        Method name = aClass.getMethod(<span class="string">"getName"</span>, <span class="keyword">null</span>);</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 传入方法的对象，以及要打印的字符串，并调用方法</span></span><br><span class="line">        say.invoke(student, <span class="string">"你好，测试invoke方法"</span>);</span><br><span class="line">        System.err.println(<span class="string">"名字："</span> + name.invoke(student));</span><br><span class="line">    &#125; <span class="keyword">catch</span> (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) &#123;</span><br><span class="line">        e.printStackTrace();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 打印结果</span></span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">你好，测试invoke方法</span></span><br><span class="line"><span class="comment">名字：赵云</span></span><br><span class="line"><span class="comment">*/</span></span><br></pre></td></tr></table></figure>

<h5 id="4-4-调用私有方法"><a href="#4-4-调用私有方法" class="headerlink" title="4.4 调用私有方法"></a>4.4 调用私有方法</h5><p>因为是私有方法，和调用公开方法的区别是需要使用<code>method.setAccessible(true)</code>，否则无法调用。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">function2</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        <span class="comment">// 得到class</span></span><br><span class="line">        Class&lt;?&gt; aClass = Class.forName(<span class="string">"reflect.Student"</span>);</span><br><span class="line">        <span class="comment">// 创建实例，并强转成学生对象</span></span><br><span class="line">        Student student = (Student) aClass.newInstance();</span><br><span class="line">        student.setName(<span class="string">"赵云"</span>);</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 得到指定的方法</span></span><br><span class="line">        Method mySay = aClass.getDeclaredMethod(<span class="string">"mySay"</span>,<span class="keyword">null</span>);</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 修改权限，否则不能调用私有方法并报错：IllegalAccessException</span></span><br><span class="line">        mySay.setAccessible(<span class="keyword">true</span>);</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 传入方法的对象，以及要打印的字符串，并调用方法</span></span><br><span class="line">        mySay.invoke(student);</span><br><span class="line">        </span><br><span class="line">    &#125; <span class="keyword">catch</span> (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) &#123;</span><br><span class="line">        e.printStackTrace();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/* 打印输出</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">这是私有方法</span></span><br><span class="line"><span class="comment">* */</span></span><br></pre></td></tr></table></figure>

<p>4.5 调用私有字段Field</p>
<ol>
<li><p>通过<code>aClass.getDeclaredField(&quot;mySex&quot;);</code>拿到私有字段</p>
</li>
<li><p>给字段设置权限，允许访问<code>mySex.setAccessible(true);</code></p>
</li>
<li><p>给私有字段赋值：<code>mySex.setAccessible(true);</code></p>
</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">function3</span><span class="params">()</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        <span class="comment">// 得到class</span></span><br><span class="line">        Class&lt;?&gt; aClass = Class.forName(<span class="string">"reflect.Student"</span>);</span><br><span class="line">        <span class="comment">// 创建实例，并强转成学生对象</span></span><br><span class="line">        Student student = (Student) aClass.newInstance();</span><br><span class="line">        <span class="comment">// 获取私有的字段</span></span><br><span class="line">        Field mySex = aClass.getDeclaredField(<span class="string">"mySex"</span>);</span><br><span class="line">        <span class="comment">// 设置权限，允许访问私有字段</span></span><br><span class="line">        mySex.setAccessible(<span class="keyword">true</span>);</span><br><span class="line">        <span class="comment">// 私有字段赋值</span></span><br><span class="line">        mySex.set(student, <span class="keyword">false</span>);</span><br><span class="line"></span><br><span class="line">        System.err.println(student.toString());</span><br><span class="line"></span><br><span class="line">    &#125; <span class="keyword">catch</span> (InstantiationException | ClassNotFoundException | NoSuchFieldException e) &#123;</span><br><span class="line">        e.printStackTrace();</span><br><span class="line">    &#125; <span class="keyword">catch</span> (IllegalAccessException e) &#123;</span><br><span class="line">        e.printStackTrace();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/* 打印结果</span></span><br><span class="line"><span class="comment">    Student&#123;name='null', age=0, mySex=false&#125;</span></span><br><span class="line"><span class="comment"> */</span></span><br></pre></td></tr></table></figure>

<p>4.6 调用私有构造函数Constructor</p>
<ol>
<li>拿到class</li>
<li>通过<code>aClass.getDeclaredConstructor(String.class, int.class, Boolean.class);</code>拿到私有构造函数</li>
<li>使用<code>setAccessible()</code>设置权限</li>
<li>使用步骤2创建好的私有构造函数，用<code>newInstance(&quot;兰陵王&quot;, 30, true)</code>创建实例并强转类型</li>
<li>打印测试结果</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">@Test</span><br><span class="line">public void function4() &#123;</span><br><span class="line">    // 得到class</span><br><span class="line">    Class&lt;?&gt; aClass = null;</span><br><span class="line">    try &#123;</span><br><span class="line">        aClass = Class.forName(&quot;reflect.Student&quot;);</span><br><span class="line">        // 创建私有构造函数，并指定参数的类型</span><br><span class="line">        Constructor&lt;?&gt; declaredConstructor = aClass.getDeclaredConstructor(String.class, int.class, Boolean.class);</span><br><span class="line">        // 设置权限，允许反射</span><br><span class="line">        declaredConstructor.setAccessible(true);</span><br><span class="line">        // 创建实例，并强转成Student对象</span><br><span class="line">        Student 兰陵王 = (Student) declaredConstructor.newInstance(&quot;兰陵王&quot;, 30, true);</span><br><span class="line">        </span><br><span class="line">        System.err.println(兰陵王.toString());</span><br><span class="line">    &#125; catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) &#123;</span><br><span class="line">        e.printStackTrace();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">/*</span><br><span class="line">打印结果：Student&#123;name=&apos;兰陵王&apos;, age=30, mySex=true&#125;</span><br><span class="line"> */</span><br></pre></td></tr></table></figure>

<h3 id="参考资料："><a href="#参考资料：" class="headerlink" title="参考资料："></a>参考资料：</h3><p><a href="[https://www.jianshu.com/p/9be58ee20dee]()">Java高级特性——反射 - 简书</a></p>
<p><a href="https://www.jianshu.com/p/f4b49e5fa443" target="_blank" rel="noopener">反射面试题 - 请了解下 - 简书</a></p>
<h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1><p>如果比较空的话，可以去做做题，体验下面试氛围，获得一点面试的经验。事实上我也确实拿到了一点面试经验，并且在后面的面试中派上用场了。用我表弟的话说：“面向经验面试”。—–2019年7月19日20:34:51</p>

      
    </div>

    <div class="article-footer" name="文章脚部">
      <blockquote class="mt-2x">
  <ul class="post-copyright list-unstyled">
    
    <li class="post-copyright-link hidden-xs">
      <strong>本文链接：</strong>
      <a href="https://blog.gobyte.cn/post/4a74da6f.html" title="01-深圳市罗湖区-中科软面试总结" target="_blank" rel="external">https://blog.gobyte.cn/post/4a74da6f.html</a>
    </li>
    
    <li class="post-copyright-license">
      <strong>版权声明： </strong> 本博客所有文章除特别声明外，均采用 <a href="http://creativecommons.org/licenses/by/4.0/deed.zh" target="_blank" rel="external">CC BY 4.0 CN协议</a> 许可协议。转载请注明出处！
    </li>
  </ul>
</blockquote>


<div class="panel panel-default panel-badger">
  <div class="panel-body">
    <figure class="media">
      <div class="media-left">
        <a href="https://github.com/shanlanCoding" target="_blank" class="img-burn thumb-sm visible-lg">
          <img src="/images/ha-002-small.png" class="img-rounded w-full" alt="">
        </a>
      </div>
      <div class="media-body">
        <h3 class="media-heading"><a href="https://github.com/shanlanCoding" target="_blank"><span class="text-dark">山岚</span><small class="ml-1x">半吊子全栈开发者</small></a></h3>
        <div>大龄萌新；新时代福娃；喜欢东搞西搞；对待问题有独到的见解；</div>
      </div>
    </figure>
  </div>
</div>


    </div>
  </article>
  
    
  <section id="comments">
  	
      <div id="vcomments"></div>
    
  </section>


  
</div>

  <nav class="bar bar-footer clearfix" data-stick-bottom>
  <div class="bar-inner">
  
  <ul class="pager pull-left">
    
    <li class="prev">
      <a href="/post/8905a03f.html" title="02-深圳市南山区-同行者科技有限公司面试总结"><i class="icon icon-angle-left" aria-hidden="true"></i><span>&nbsp;&nbsp;上一篇</span></a>
    </li>
    
    
    <li class="next">
      <a href="/post/738b9ed9.html" title="MIUI真的负优化吗？"><span>下一篇&nbsp;&nbsp;</span><i class="icon icon-angle-right" aria-hidden="true"></i></a>
    </li>
    
    
    <li class="toggle-toc">
      <a class="toggle-btn collapsed" data-toggle="collapse" href="#collapseToc" aria-expanded="false" title="文章目录" role="button">
        <span>[&nbsp;</span><span>文章目录</span>
        <i class="text-collapsed icon icon-anchor"></i>
        <i class="text-in icon icon-close"></i>
        <span>]</span>
      </a>
    </li>
    
  </ul>
  
  
  
  <div class="bar-right">
    
  </div>
  </div>
</nav>
  



  	<script>
	  <!-- 百度站长自动推送链接 -->
		(function(){
		var bp = document.createElement('script');
		var curProtocol = window.location.protocol.split(':')[0];
		if (curProtocol === 'https') {
			bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
		}
		else {
			bp.src = 'http://push.zhanzhang.baidu.com/push.js';
		}
		var s = document.getElementsByTagName("script")[0];
		s.parentNode.insertBefore(bp, s);
		})();
	</script>
</main>

  <footer class="footer" itemscope itemtype="http://schema.org/WPFooter">
	
	
    <ul class="social-links">
    	
        <li><a href="https://github.com/shanlanCoding" target="_blank" title="Github" data-toggle=tooltip data-placement=top><i class="icon icon-github"></i></a></li>
        
        <li><a href="http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=CWRgen1se2phZnxJeHgnamZk" target="_blank" title="Email" data-toggle=tooltip data-placement=top><i class="icon icon-email"></i></a></li>
        
    </ul>



	<div class="powered-by" name="不蒜子" sytle="font-size:12px">
		<i class="icon icon-users"></i>
		<span id="busuanzi_container_site_uv">
			总访客 : <span id="busuanzi_value_site_uv"></span>
		</span><br/>
		<i class="icon icon-eye-fill"></i>
		<span id="busuanzi_container_site_pv">
		    总阅读 : <span id="busuanzi_value_site_pv"></span>
		</span>
	</div>
    
	<div class="copyright" name="作者">
		
		<div class="publishby">
			Theme by <a href="https://github.com/cofess" target="_blank"> cofess </a>base on <a href="https://github.com/cofess/hexo-theme-pure" target="_blank">pure</a>.
		</div>
	</div>

</footer>
  <script src="//cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>

<script>
	window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')

		<!-- 百度统计 -script.ejs --> 
		var _hmt = _hmt || [];
		(function() {
		  var hm = document.createElement("script");
		  hm.src = "https://hm.baidu.com/hm.js?e003775b21b75a71e1396c1fc395cce7";
		  var s = document.getElementsByTagName("script")[0]; 
		  s.parentNode.insertBefore(hm, s);
		})();

		<!-- 新浪云防盗链 -->
		var link = "" ;
		setTimeout( function(){
			$("img").each( (i,o) => {
				var o = $(o);
				if(o.attr("src").indexOf("sinaimg") > 0 ){
					o.attr("referrerpolicy","no-referrer");
					link = o.attr("src");
					o.attr("src",link);
				}
			});
		},1000);

</script>

<script src="/js/plugin.min.js"></script>
<script src="/js/application.js"></script>

    <script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(未命名)',
        },
        ROOT_URL: '/',
        CONTENT_URL: '/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>
<script src="/js/insight.js"></script>






	
   
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>




   
    
  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/valine"></script>
  <script type="text/javascript">
  var GUEST = ['nick', 'mail', 'link'];
  var meta = 'nick,mail,link';
  meta = meta.split(',').filter(function(item) {
    return GUEST.indexOf(item) > -1;
  });
  new Valine({
    el: '#vcomments',
    verify: false,
    notify: false,
    appId: 'ksrz2lYRLkGCOqMraVC2gBB3-gzGzoHsz',
    appKey: 'ehlbHl0wgN6gbvN4NQexYxnl',
    placeholder: '说点什么吧？',
    avatar: 'robohash',
    meta: meta,
    pageSize: '10' || 10,
    visitor: true
  });
  </script>

     







</body>
</html>